package com.zx.map.dao.impl;

import com.zx.map.dao.ShareProfitDetailLogDao;
import com.zx.map.dao.mapper.ShareProfitDetailLogMapper;
import com.zx.map.dao.model.ShareProfitDetailLog;
import com.zx.map.dao.model.ShareProfitDetailLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA. User: Administrator Date: 14-3-1 Time: 上午10:54 To
 * change this template use File | Settings | File Templates.
 */
@Component("shareProfitDetailLogDao")
public class ShareProfitDetailLogImpl implements ShareProfitDetailLogDao {

    @Autowired
    private ShareProfitDetailLogMapper mapper;

    /**
     * 新增
     */
    public String add(ShareProfitDetailLog shareProfitDetailLog) throws DataAccessException {
        int column = mapper.insert(shareProfitDetailLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return shareProfitDetailLog.getSpDetailId().toString();
    }

    /**
     * 修改
     *
     * @param shareProfitDetailLog
     * @return
     * @throws DataAccessException
     */
    public String update(ShareProfitDetailLog shareProfitDetailLog)
            throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(shareProfitDetailLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return shareProfitDetailLog.getSpDetailId().toString();
    }

    /**
     * 按主键删除
     */
    public void deleteByPrimaryKey(ShareProfitDetailLog shareProfitDetailLog)
            throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(shareProfitDetailLog.getSpDetailId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     * 删除
     */
    public void delete(ShareProfitDetailLogExample example)
            throws DataAccessException {
        int column = mapper.deleteByExample(example);
    }

    /**
     *
     */
    public List<ShareProfitDetailLog> getListByExample(ShareProfitDetailLogExample example)
            throws DataAccessException {
        return mapper.selectByExample(example);
    }

    /**
     *
     */
    public int countListByExample(ShareProfitDetailLogExample example)
            throws DataAccessException {
        return mapper.countByExample(example);
    }

    /**
     * 查询总收益
     * @param example
     * @return
     */
    @Override
    public Double queryTotalSpDetailAmtByExample(ShareProfitDetailLogExample example) {
        return mapper.queryTotalSpDetailAmtByExample(example);
    }

    /**
     * 分页查找
     */
    public List<ShareProfitDetailLog> getPageByExample(int pageSize, int pageBegin,
                                                       ShareProfitDetailLogExample example) throws DataAccessException {
        return mapper.getPageByModel(pageSize, pageBegin, example);
    }
}
